<?php

namespace App\Admin\Resources;

class AdminOperationLogResource extends JsonResource
{
    const FOR_INDEX = 'index';
    const FOR_SHOW = 'show';

    public function toArray($request)
    {
        $data = [
            'admin_user' => $this->mergeAdminUser(),
        ];
        return array_merge(parent::toArray($request),$data);
    }

    protected function mergeAdminUser()
    {
        return [
            $this->mergeFor(static::FOR_INDEX, function () {
                return $this->adminUser()->withTrashed(isRestore())->first() ?? [];
            }),
            $this->mergeFor(static::FOR_SHOW, function () {
                return $this->adminUser()->withTrashed(isRestore())->first() ?? [];
            }),
        ];
    }
}
